package com.qy127.javaweb.dao.impl;



import com.qy127.javaweb.dao.T_roleDao;
import com.qy127.javaweb.entity.T_role;
import com.qy127.javaweb.util.JDBCUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class T_roleDaoimpl implements T_roleDao {

    @Override
    public List<T_role> getall() {
        String sql="select rid,  rname, memo, status  from t_role";
        List<Map<String, Object>> maps = JDBCUtil.queryListMap(sql);
        ArrayList<T_role> list = new ArrayList<>();
        if (maps.size()>0){
            for (Map<String, Object> map : maps) {
                T_role role = new T_role((Integer) map.get("rid"), (String) map.get("rname"), (String) map.get("memo"), (Integer) map.get("status"));
                list.add(role);
            }
            return list;
        }else {
            return null;
        }
    }

    /**
     * 添加人员
     * @param aa
     * @return
     */
    @Override
    public int add(T_role aa) {
        String sql="insert into t_role value(?,?,?,?)";
        int i = JDBCUtil.update(sql, null, aa.getRname(), aa.getMemo(), aa.getStatus());
        return i;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public int dele(Integer id) {
        String sql="delete from t_role where rid=? ";
        int i = JDBCUtil.update(sql, id);
        return i;

    }

    /**
     * 修改前赋值
     * @param id
     * @return
     */
    @Override
    public T_role getone(Integer id) {
        String sql="select  rid,  rname, memo, status  from t_role where rid=?";
        List<List> lists = JDBCUtil.queryList(sql, id);
        if (lists.size()>0){
            List list = lists.get(0);
            T_role role = new T_role((Integer) list.get(0), (String) list.get(1), (String) list.get(2), (Integer) list.get(3));
            return role;
        }
        return  null;
    }

    /**
     * 修改
     * @param rname
     * @param memo
     * @param status
     * @param id
     * @return
     */
    @Override
    public int ua(String rname, String memo,Integer status ,Integer id) {
        String sql="update  t_role set rname=?, memo=?, status=? where rid=?";
        int i = JDBCUtil.update(sql, rname , memo , status ,id);
        return  i;
    }


}
